package com.xinxing.city.recoverycheck.sdk_ttys;




public class DecodeAc {

    public static void DecodeAcPacket1() {

        try {

            // 构造一个收到的报文
            byte[] buffer = Hexs.HexToByte("aaac01000000000000000000000000000000000000090000010002931f0a");
            String recvPacke = Hexs.ByteToHex(buffer);
            byte[] b3 = Hexs.HexToByte(recvPacke);
            System.out.println("Hexs：" + recvPacke);
            System.out.println("byte length：" + b3.length);

            // 解码
            System.out.println("isPack：" + AcPackage.isPack(b3));

            if(AcPackage.isPack(b3)){
                AcPackage p = new AcPackage(b3);
                System.out.println("解码：0x" + Hexs.ByteToHex(new byte[]{p.frame}));
                System.out.println("解码body：" + Hexs.ByteToHex(p.body));
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }



    }

    // 编码 开门示例
    public static void open_door() {

        // 编码
        AcPackage p2 = new AcPackage();

        System.out.println("编码后的HEX格式：" + AcPackage.isPack(p2.getPackage()));

        byte ACdoorId=1;
        String orderid="964b71d3a305d7d97116783592470002";
        p2.frame = 0x05;
        p2.body = Hexs.byteMerger(new byte[]{ACdoorId}, Hexs.HexTobyte(orderid));

        byte[] _package = p2.getPackage();
        send_cmd(_package);
    }
    public static void open_lock_door(){
        // 编码
        AcPackage p2 = new AcPackage();

        System.out.println("编码后的HEX格式：" + AcPackage.isPack(p2.getPackage()));

        byte ACdoorId=1;
        String orderid="964b71d3a305d7d97116783592470002";
        p2.frame = 0x0B;
        p2.body = Hexs.byteMerger(new byte[]{ACdoorId}, Hexs.HexTobyte(orderid));

        byte[] _package = p2.getPackage();
        send_cmd(_package);
    }
    public static void select_state(){
        AcPackage p2 = new AcPackage();

        System.out.println("编码后的HEX格式：" + AcPackage.isPack(p2.getPackage()));

//        byte ACdoorId=1;
//        String orderid="964b71d3a305d7d97116783592470002";
        p2.frame = 0x03;
        p2.body = Hexs.byteMerger(new byte[]{});

        byte[] _package = p2.getPackage();
        send_cmd(_package);
    }
    public static void reb_07(){
        byte ACdoorId=1;
        String orderid="964b71d3a305d7d97116783592470002";
        AcPackage p = new AcPackage();
        p.frame = 0x08;

        p.body = Hexs.byteMerger(new byte[]{ACdoorId}, Hexs.HexTobyte(orderid));
        byte[] _package = p.getPackage();
        String hex = Hexs.ByteToHex(_package);

        System.out.println("编码后的HEX格式：" + hex );

        send_cmd(_package);
    }

    // 编码
    public static void close_door() {

        byte ACdoorId=1;

        AcPackage p = new AcPackage();
        p.frame = 0x09;
        p.body = Hexs.byteMerger(new byte[]{(byte) ACdoorId});
        byte[] _package = p.getPackage();
        String hex = Hexs.ByteToHex(_package);

        System.out.println("编码后的HEX格式：" + hex );

        send_cmd(_package);
    }



    // 将数据写到串口
    private static void send_cmd(byte[] buffer) {

//        MainActivity.send_cmd(buffer);


    }


}
